package net.wangds.auth.account.entity;

import net.wangds.auth.module.Account;
import net.wangds.auth.module.UserStatusEnum;
import net.wangds.auth.module.impls.defaults.DefaultAccount;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Collection;

@Entity
@Table(name="auth_account")
public class GeneralAccountEntity extends DefaultAccount implements UserDetails {
    private static final long serialVersionUID = 0;

    public static Account of(String accountId) {
        GeneralAccountEntity res = new GeneralAccountEntity();
        res.setId(accountId);
        return res;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getUsername() {
        return this.getLoginname();
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.getStatus() == UserStatusEnum.NORMAL;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.getStatus() == UserStatusEnum.NORMAL;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return this.getStatus() == UserStatusEnum.NORMAL;
    }
}
